import java.util.InputMismatchException;
import java.util.Scanner;
class ArrayUtils{
	public static double findMax(double[] arr,int begin, int end) throws IllegalArgumentException 
	{
		double max=arr[0];
		if(begin>=end)
		{
			throw new IllegalArgumentException("begin:"+begin+" >= end:"+end);
		}
		if(begin<0)
		{

			throw new IllegalArgumentException("begin:"+begin+" < 0");
		}
		if(end>arr.length)
		{
			throw new IllegalArgumentException("end:"+end+" > arr.length");	
		}
		for(int i=begin;i<end;i++)
		{
				if(arr[i]>max) max=arr[i];
		}
		return max;
		
	}	 

}

public class Main {

	public static void main(String[] args) throws IllegalArgumentException{
		Scanner input=new Scanner(System.in);
		int n=input.nextInt();
		double[]arr=new double[n];
		for(int i=0;i<n;i++){
			arr[i]=input.nextDouble();
		}
		while(true){
			try{  
				int begin=Integer.parseInt(input.next());
		 		int end=Integer.parseInt(input.next());
		 		System.out.println(ArrayUtils.findMax(arr,begin,end));
		}catch(NumberFormatException e){
        	   break;
           }
		 catch(Exception e){
			System.out.println(e);
		}
		}
		try {
		     System.out.println(ArrayUtils.class.getDeclaredMethod("findMax", double[].class,int.class,int.class));
		} catch (Exception e1) {
		}
		

	}
	
}
